import React, { Component } from 'react'
import routerConfig from "./routerConfig"
import { NavLink } from 'react-router-dom'
import { Menu } from "antd"
export class RouterLink extends Component {
  constructor(props) {
    super(props)

    this.state = {
      keyPath: []
    }
  }
  componentDidMount() {
    let keyPath = localStorage.getItem("keyPath") ?
      JSON.parse(localStorage.getItem("keyPath")) :
      ['/dash/fenxi', "0"]
    this.setState({
      keyPath: keyPath
    })
  }




  render() {
    let { keyPath } = this.state
    return (
      <div>
        <Menu mode="inline"
          openKeys={[keyPath[1]]}
          selectedKeys={[keyPath[0]]}
          onClick={(obj) => {
            const { keyPath } = obj
            localStorage.setItem("keyPath", JSON.stringify(keyPath))
            this.setState({
              keyPath
            })
          }}
          onOpenChange={(e) => {
            console.log('e', e)
            keyPath[1] = e[1]
            this.setState({
              keyPath
            })

          }

          }
        >

          {routerConfig.length ? routerConfig.map((item, index) => {
            return item.show ? <Menu.SubMenu key={index} title={item.title} >
              {
                item.children ? item.children.map((v, i) => {
                  return <Menu.Item key={v.path}><NavLink to={v.path}>{v.title}</NavLink></Menu.Item>
                }) : '暂无数据'
              }
            </Menu.SubMenu> : null
          }) : '暂无数据'

          }
        </Menu>
      </div>
      // <div>{
      //     routerConfig ?routerConfig.map((item,index)=>{
      //         return  item.show  ?
      //         <div>
      //              <h2 className='yi'>
      //                  <NavLink to={item.path}>{item.title}</NavLink>
      //               </h2>
      //              <div className='er'>
      //                   {item.children  ?item.children.map((v,i)=>{
      //                  return v.show ?
      //                   <h4> <NavLink to={v.path}> {v.title}</NavLink></h4>:null
      //              }):'暂无数据'}</div></div>:null
      //     })
      //     :'暂无数据'

      //     }

      // </div>
    )
  }
}

export default RouterLink